package com.szh.zx.gaoDingJavaBook.yitu.one;

import java.util.HashMap;

public class HashMapTest1 {
	public static void main(String[] args) {
		Student1 student1 = new Student1(12, "ddd");
		Student1 student2 = new Student1(12, "ddd");
		HashMap<Student1, String> map = new HashMap<>();
		map.put(student1,"ddd");
		map.put(student2,"ddd");
		System.out.println(map.size());
	}
}
class Student1{
	int age;
	String name;

	public Student1(int age, String name) {
		this.age = age;
		this.name = name;
	}

	@Override
	public String toString() {
		return "Student1{" +
				"age=" + age +
				", name='" + name + '\'' +
				'}';
	}

	@Override
	public boolean equals(Object obj) {
		if (obj ==null){
			return false;
		}
		if (!(obj instanceof Student1)){
			return false;
		}
		if (obj==this) {
			return true;
		}
		Student1 student1 = this;
		Student1 student2 = (Student1) obj;
		return student1.name.equals(student2.name)&& student1.age ==student2.age;
	}

	@Override
	public int hashCode() {
		return name.hashCode()+age;
	}
}